package com.example.shushiyunsst.fragment.main.home.recycler.provider;

import android.content.Context;
import android.view.View;

import com.example.library_common.adapter.multi.JssMultiItemViewHolder;
import com.example.library_common.adapter.multi.JssNewMultipleAdapter;
import com.example.library_common.album.view.grid_view.XGridLayout;
import com.example.library_common.album.view.grid_view.adapter.CommAdapter;
import com.example.library_common.album.view.grid_view.adapter.XQuickViewHolder;
import com.example.shushiyunsst.R;
import com.example.shushiyunsst.fragment.main.home.recycler.bean.CurrencyEntity;
import com.example.shushiyunsst.fragment.main.home.recycler.bean.CurrencyEntityWrapper;

public class CurrencyProvider extends JssMultiItemViewHolder<CurrencyEntityWrapper> {

    private CommAdapter<CurrencyEntity>mAdapter;

    public CurrencyProvider(View view) {
        super(view);
    }

    @Override
    public int getItemLayout() {
        return R.layout.currency_provider_layout;
    }

    @Override
    public void convert(Context context, CurrencyEntityWrapper currencyEntityWrapper) {
        super.convert(context, currencyEntityWrapper);
        XGridLayout mLineLayout = findView(R.id.mLineLayout);
        if (mAdapter==null){
            mAdapter=new CommAdapter<CurrencyEntity>(
                    context ,
                    R.layout.currency_provider_item_layout
                    ) {
                @Override
                public void convert(XQuickViewHolder holder, CurrencyEntity item, int position) {
                    holder.setText(R.id.currency_name,item.getTokenName()+"")
                            .setText(R.id.currency_time,item.getTimes()+"")
                            .setText(R.id.currency_new_price,item.getTokenNums()+"")
                            .setText(R.id.currency_new_sub_price,"≈"+item.getTokenPrice()+"CNY")
                            .setText(R.id.currency_new_rise,item.getUpdown()+"");
                }
            };
        }
        if (mLineLayout!=null){
            if (adapter instanceof JssNewMultipleAdapter){
                mLineLayout.setAdapter(mAdapter,((JssNewMultipleAdapter) adapter).getLifecycle());
            }

        }

        mAdapter.clear();
        mAdapter.addAll(currencyEntityWrapper.getList());
    }
}
